@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">添加商品</h5>
                </div>
                <div class="card-body">
                    <form action="{{ route('products.store') }}" method="POST" enctype="multipart/form-data">
                        @csrf
                        <div class="row g-3">
                            <div class="col-12 col-md-6">
                                <div class="mb-4">
                                    <label for="name" class="form-label fw-semibold">商品名称</label>
                                    <input type="text" class="form-control @error('name') is-invalid @enderror"
                                        id="name" name="name" value="{{ old('name') }}"
                                        placeholder="请输入商品名称" required>
                                    @error('name')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="mb-4">
                                    <label for="price" class="form-label fw-semibold">商品价格</label>
                                    <input type="number" class="form-control @error('price') is-invalid @enderror"
                                        id="price" name="price" value="{{ old('price') }}"
                                        placeholder="输入商品单价" step="0.01" required>
                                    @error('price')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="mb-4">
                                    <label for="stock" class="form-label fw-semibold">库存数量</label>
                                    <input type="number" class="form-control @error('stock') is-invalid @enderror"
                                        id="stock" name="stock" value="{{ old('stock', 0) }}"
                                        placeholder="设置初始库存量" min="0" required>
                                    @error('stock')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="mb-4">
                                    <label for="status" class="form-label fw-semibold">商品状态</label>
                                    <select class="form-select @error('status') is-invalid @enderror"
                                        id="status" name="status" aria-describedby="statusHelp" required>
                                        <option value="" disabled>请选择商品状态</option>
                                        <option value="1" {{ old('status') == '1' ? 'selected' : '' }}>上架</option>
                                        <option value="0" {{ old('status') == '0' ? 'selected' : '' }}>下架</option>
                                    </select>
                                    @error('status')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                    <small id="statusHelp" class="form-text text-muted mt-1">上架后商品将立即展示在商城页面</small>
                                </div>
                            </div>

                            <div class="col-12 col-md-6">
                                <div class="mb-4">
                                    <label for="description" class="form-label fw-semibold">商品描述</label>
                                    <textarea class="form-control @error('description') is-invalid @enderror"
                                        id="description" name="description" rows="4"
                                        placeholder="详细描述商品特性">{{ old('description') }}</textarea>
                                    @error('description')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                </div>

                                <div class="mb-4">
                                    <label for="main_image" class="form-label fw-semibold">商品主图</label>
                                    <input type="file" class="form-control @error('main_image') is-invalid @enderror"
                                        id="main_image" name="main_image" accept="image/*"
                                        aria-describedby="mainImageHelp">
                                    @error('main_image')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                    <small id="mainImageHelp" class="form-text text-muted mt-1">建议尺寸：800x800像素，支持JPG/PNG格式</small>
                                </div>

                                <div class="mb-4">
                                    <label for="images" class="form-label fw-semibold">商品图片集</label>
                                    <input type="file" class="form-control @error('images') is-invalid @enderror"
                                        id="images" name="images[]" accept="image/*" multiple
                                        aria-describedby="imagesHelp">
                                    @error('images')
                                    <div class="invalid-feedback d-block mt-1">{{ $message }}</div>
                                    @enderror
                                    <small id="imagesHelp" class="form-text text-muted mt-1">最多可上传10张展示图片，每张不超过5MB</small>
                                </div>
                            </div>
                        </div>

                        <div class="d-flex gap-2 justify-content-end mt-4">
                            <a href="{{ route('products.index') }}" class="btn btn-outline-secondary px-4">返回</a>
                            <button type="submit" class="btn btn-primary px-4">保存商品</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection